<template>
  <div>
    <ul>
      <li :style="{ opacity }">欢迎学习</li>
      <li v-for="news in newList" :key="news.id1">
        <router-link
          :to="{
            name: 'nxiangqing',
            params: {
              id: news.id1,
              title: news.title1,
            },
          }"
          >{{ news.title1 }}</router-link
        >
      </li>
    </ul>
    <br />
    <br />
    <div><router-view></router-view></div>
  </div>
</template>

<script>
export default {
  name: "News",
  data() {
    return {
      newList: [
        { id1: "001", title1: "消息001" },
        { id1: "002", title1: "消息002" },
        { id1: "003", title1: "消息003" },
      ],
      opacity: 1,
    };
  },
  beforeDestroy() {
    console.log("new 将要被销毁了");
  },

  activated() {
    console.log("activated被激活了");
    this.timer = setInterval(() => {
      this.opacity -= 0.1;
      if (this.opacity < 0) {
        this.opacity = 1;
      }
    }, 500);
  },
  deactivated() {
    console.log("deactivated被激活了", this);
    clearInterval(this.timer);
  },
};
</script>